package logic;

import java.awt.Color;

/**
 *
 * @author christ66
 */
public class Player {

    public Player(String nickName) {
        this.nickName = nickName;
        if (Math.random() > 0.5) {
            color = Color.black;
            myTurn = false;
        }
        else {
            color = Color.white;
            myTurn = true;
        }
    }

    // Hoster is color white by default.
    // Rival is color black by default.
    public Player(String nickName, Color color) {
        this.nickName = nickName;
        this.color = color;
        if (Color.white.equals(this.color))
            myTurn = true;
        else
            myTurn = false;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color c){
        color = c;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public boolean isMyTurn() {
        return myTurn;
    }

    public void setMyTurn(boolean turn) {
        myTurn = turn;
    }
    
    public void randomColor() {
        if (Math.random() > 0.5) {
            setColor(Color.black);
            myTurn = false;
        }
        else {
        	setColor(Color.white);
            myTurn = true;
        }
    }


    public void switchTurn() {
        myTurn ^= true; // Leave this, it's an XOR boolean switch.
    }

    @Override
    public String toString() {
        //return "[nickName=" + nickName + ";Color=" + color.toString() + "]";
    	String s = "[nickName=" + nickName + ";";
    	if (getColor()==Color.WHITE) {
    		s+="white" + "]";
    	} else {
    		s+="black" + "]";
    	}
    	return s;
    }

    private static String nickName;
    private static boolean myTurn;
    private static Color color;
}
